import {ILogger, LogLevel} from './ILogger'
import {LoggerManager} from './LoggerManager'

class TLog implements ILogger {
    private LogImpl:ILogger | undefined = undefined
    private mPrefix:string = '[TLog]'
    public static isDebug = true;
    public static sLogLevel:LogLevel = LogLevel.DEBUG
    constructor(prefix:string) {
        this.mPrefix = prefix
        this.LogImpl = LoggerManager.getInstance().createLogger(prefix)
    }

    getDomain() {
        return this.LogImpl.getDomain();
    }

    getPrefix() {
        return this.LogImpl.getPrefix();
    }

    getFormat() {
        return this.LogImpl.getFormat();
    }

    debug(...args:string[]):void {
        if (TLog.isDebug && TLog.sLogLevel <= LogLevel.DEBUG) {
            if (args.length == 1) {
                args.unshift(this.mPrefix)
            }
            this.LogImpl.debug(...args);
        }
    }


    info(...args:string[]):void {
         if (TLog.isDebug && TLog.sLogLevel <= LogLevel.INFO) {
             if (args.length == 1) {
                 args.unshift(this.mPrefix)
             }
             this.LogImpl.info(...args);
         }
    }

    warn(...args:string[]):void {
         if (TLog.isDebug && TLog.sLogLevel <= LogLevel.WARN) {
             if (args.length == 1) {
                 args.unshift(this.mPrefix)
             }
             this.LogImpl.warn(...args)
         }
    }

    error(...args:string[]):void {
        if (TLog.isDebug && TLog.sLogLevel <= LogLevel.ERROR) {
            if (args.length == 1) {
                args.unshift(this.mPrefix)
            }
            this.LogImpl.error(...args)
        }
    }
}

export default new TLog('[TLog]')